/*	=======================================================================
	<remarks>
	Version:
		- number:	1.0.0	
		- build:	20070423
		- status:	dev
	</remarks>
	======================================================================= */

/*	-----------------------------------------------------------------------
	Check and drop Function(s)
	-----------------------------------------------------------------------	*/

/*	-----------------------------------------------------------------------
	Check and drop standard Procedure(s)
	-----------------------------------------------------------------------	*/
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProfileList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[ProfileList]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProfileAdd]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[ProfileAdd]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProfileUpdate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[ProfileUpdate]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProfileRemove]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[ProfileRemove]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProfileGet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[ProfileGet]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CategoryList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[CategoryList]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CategoryAdd]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[CategoryAdd]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CategoryUpdate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[CategoryUpdate]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CategoryRemove]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[CategoryRemove]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CategoryGet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[CategoryGet]
	GO
	
/*	-----------------------------------------------------------------------
	Check and drop custom Procedure(s)
	-----------------------------------------------------------------------	*/
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[RecordYou]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[RecordYou]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[RecordCell]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[RecordCell]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[RecordSite]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[RecordSite]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[RecordHome]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[RecordHome]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[RecordBilling]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[RecordBilling]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[RecordService]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[RecordService]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[RecordInternet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[RecordInternet]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[RecordTesting]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[RecordTesting]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[RecordGet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[RecordGet]
	GO
	
/*	-----------------------------------------------------------------------
	Check and drop Tables
	-----------------------------------------------------------------------	*/
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Profiles]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table [dbo].[Profiles]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProfileCell]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table [dbo].[ProfileCell]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProfileSite]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table [dbo].[ProfileSite]
	GO

	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProfileHome]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table [dbo].[ProfileHome]
	GO

	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProfileBilling]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table [dbo].[ProfileBilling]
	GO

	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProfileService]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table [dbo].[ProfileService]
	GO

	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProfileInternet]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table [dbo].[ProfileInternet]
	GO
 
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Categories]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table [dbo].[Categories]
	GO
	
	if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProfCatLink]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	drop table [dbo].[ProfCatLink]
	GO
	
/*	-----------------------------------------------------------------------
	Create Tables
	-----------------------------------------------------------------------	*/
	/*	---------------------------------
		The core profile of personal info
		---------------------------------	*/
	CREATE TABLE [dbo].[Profiles] (
		[ID] [int] IDENTITY (1, 1) NOT NULL ,
		[StatusID] [int] NOT NULL ,
		[Title] [varchar] (10) COLLATE Latin1_General_CI_AS NULL ,
		[Firstname] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
		[Surname] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
		[Email] [varchar] (100) COLLATE Latin1_General_CI_AS NULL ,
		[Cellphone] [varchar] (30) COLLATE Latin1_General_CI_AS NULL ,
		[Age] [varchar] (10) COLLATE Latin1_General_CI_AS NULL ,
		[Profession] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
		[Customer] [varchar] (5) COLLATE Latin1_General_CI_AS NULL ,
		[Registered] [varchar] (5) COLLATE Latin1_General_CI_AS NULL ,
		[Testing] [varchar] (5) COLLATE Latin1_General_CI_AS NULL ,
		[InitDate] [datetime] NULL ,
	) ON [PRIMARY]
	GO
	
	CREATE TABLE [dbo].[ProfileCell] (
		[ProfileID] [int] NOT NULL ,
		[HowOften] [int] NULL ,
		[Choose] [varchar] (100) COLLATE Latin1_General_CI_AS NULL ,
		[ChooseOther] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Use] [varchar] (100) COLLATE Latin1_General_CI_AS NULL ,
		[UseOther] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Costs] [varchar] (10) COLLATE Latin1_General_CI_AS NULL ,
		[Pay] [varchar] (10) COLLATE Latin1_General_CI_AS NULL ,
		[PayOther] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Contract] [varchar] (10) COLLATE Latin1_General_CI_AS NULL ,
	) ON [PRIMARY]
	GO
	
	CREATE TABLE [dbo].[ProfileSite] (
		[ProfileID] [int] NOT NULL ,
		[Think] [int] NULL ,
		[ThinkWhy] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[ChangeMost] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Change] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[ChangeLeast] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[LikeMost] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Like] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[LikeLeast] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Nav] [int] NULL ,
		[NavWhy] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Looks] [int] NULL ,
		[LooksWhy] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Speed] [int] NULL ,
		[More] [varchar] (2000) COLLATE Latin1_General_CI_AS NULL ,
	) ON [PRIMARY]
	GO
	
	CREATE TABLE [dbo].[ProfileHome] (
		[ProfileID] [int] NOT NULL ,
		[Think] [int] NULL ,
		[ThinkWhy] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Separate] [int] NULL ,
		[SeparateWhy] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[ChangeMost] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Change] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[ChangeLeast] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[LikeMost] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Like] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[LikeLeast] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Prefer] [varchar] (100) COLLATE Latin1_General_CI_AS NULL ,
		[PreferOther] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[BypassMost] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Bypass] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[BypassLeast] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[More] [varchar] (2000) COLLATE Latin1_General_CI_AS NULL ,
	) ON [PRIMARY]
	GO

	CREATE TABLE [dbo].[ProfileBilling] (
		[ProfileID] [int] NOT NULL ,
		[Prefer] [varchar] (100) COLLATE Latin1_General_CI_AS NULL ,
		[Think] [int] NULL ,
		[ThinkWhy] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[ChangeMost] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Change] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[ChangeLeast] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[LikeMost] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Like] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[LikeLeast] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Add] [varchar] (10) COLLATE Latin1_General_CI_AS NULL ,
		[AddWhat] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[More] [varchar] (2000) COLLATE Latin1_General_CI_AS NULL ,
	) ON [PRIMARY]
	GO

	CREATE TABLE [dbo].[ProfileService] (
		[ProfileID] [int] NOT NULL ,
		[Prefer] [varchar] (100) COLLATE Latin1_General_CI_AS NULL ,
		[PreferOther] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[PreferWhy] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Think] [int] NULL ,
		[ThinkWhy] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Site] [varchar] (10) COLLATE Latin1_General_CI_AS NULL ,
		[SiteWhy] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[AddMost] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Add] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[AddLeast] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[More] [varchar] (2000) COLLATE Latin1_General_CI_AS NULL ,
	) ON [PRIMARY]
	GO

	CREATE TABLE [dbo].[ProfileInternet] (
		[ProfileID] [int] NOT NULL ,
		[Know] [varchar] (10) COLLATE Latin1_General_CI_AS NULL ,
		[Location] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
		[UseMost] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Use] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[UseLeast] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[ImportantMost] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Important] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[ImportantLeast] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[AddMost] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Add] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[AddLeast] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[More] [varchar] (2000) COLLATE Latin1_General_CI_AS NULL ,
	) ON [PRIMARY]
	GO

	/*	profile categories	*/
	CREATE TABLE [dbo].[Categories] (
		[ID] [int] IDENTITY (1, 1) NOT NULL ,
		[Name] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
		[Description] [varchar] (5000) COLLATE Latin1_General_CI_AS NULL
	) ON [PRIMARY]
	GO
	
	CREATE TABLE [dbo].[ProfCatLink] (
		[ProfileID] [int] NULL ,
		[CategoryID] [int] NULL
	) ON [PRIMARY]
	GO
	
	
/*	-----------------------------------------------------------------------
	Create Procedures
	-----------------------------------------------------------------------	*/
	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	CREATE Procedure ProfileList (@CategoryID int)
	/*	-----------------------------------------------------------------------
		Procedure: ProfileList
			- Stored procedure for getting profiles
			- By category or all
		Parameters:
			@CategoryID:	Category identifier
		Returns:
			0:	Success
			n:	Some error condition
		-----------------------------------------------------------------------	*/
	As
		Begin
			-- Declarations:
			-- Code:
			Select
				[ProfileID],
				[StatusID],
				[CategoryID],
				[CategoryName] = Categories.Name,
				[Title],
				[Firstname],
				[Surname],
				[Email],
				[Cellphone],
				[InitDate]
			From ProfCatLink
				Inner Join Categories on ProfCatLink.CategoryID = Categories.ID
				Inner Join Profiles on ProfCatLink.ProfileID = Profiles.ID
				Where CategoryID = @CategoryID or @CategoryID = 0
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO
	
	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: ProfileGet
			- Stored procedure for getting profile profiles
			- By profile or all
		Parameters:
			@ProfileID:	The profile identifier
		Returns:
			0:	Success
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure ProfileGet (@ProfileID int)
		As
		Begin
			-- Declarations:
			-- Code:
			Select 
				[ID] = Profiles.ID,
				[StatusID],
				[CategoryID],
				[CategoryName] = Categories.Name,
				[Title],
				[Firstname],
				[Surname],
				[Email],
				[Cellphone],
				[InitDate]
			From ProfCatLink
				Inner Join Categories on ProfCatLink.CategoryID = Categories.ID
				Inner Join Profiles on ProfCatLink.ProfileID = Profiles.ID
				Where [ProfileID] = @ProfileID
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO
	
	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: ProfileAdd
			- Stored procedure to add a new profile
		Parameters:
			@CategoryID:	Category identifier
			@Name:			Name of the profile
			@Email:			Email of the profile
		Returns:
			0:	Success
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure ProfileAdd (
			@CategoryID int, 
			@Title varchar(10),
			@Firstname varchar(50),
			@Surname varchar(50),
			@Email varchar(100),
			@Cellphone varchar(30)
		)
		As
		Begin
			-- Declarations:
			Declare @profid int
			-- Code:
			Insert into Profiles([StatusID], [Title], [Firstname], [Surname], [Email], [Cellphone], [InitDate])
				Values(1, @Title, @Firstname, @Surname, @Email, @Cellphone, GetDate())
			Set @profid = @@IDENTITY
			Insert into ProfCatLink([ProfileID], [CategoryID])
				Values(@profid, @CategoryID)
			Exec ProfileGet @profid
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO
	
	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: ProfileUpdate
			- Stored procedure to update a profile
		Parameters:
			@ProfileID:		The profile identifier
			@Name:			Name of the profile
			@Email:			Email of the profile
		Returns:
			0:	Success
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure ProfileUpdate (
			@ProfileID int,
			@Title varchar(10),
			@Firstname varchar(50),
			@Surname varchar(50),
			@Email varchar(100),
			@Cellphone varchar(30)
		)
		As
		Begin
			Update Profiles
				Set 
					[Title] = @Title,
					[Firstname] = @Firstname,
					[Surname] = @Surname,
					[Email] = @Email,
					[Cellphone] = @Cellphone
				Where [ID] = @ProfileID
			Exec ProfileGet @ProfileID
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO
	
	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: ProfileRemove
			- Stored procedure to remove a profile
			- Removes the profiles and all links to categories
		Parameters:
			@ProfileID:	The profile identifier
		Returns:
			0:	Success
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure ProfileRemove (@ProfileID int)
		As
		Begin
			-- Code:
			Delete From ProfCatLink
				Where [ProfileID] = @ProfileID
			Delete From Profiles
				Where [ID] = @ProfileID
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO
	
	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: CategoryList
			- Stored procedure for getting profile categories
		Parameters:
			none
		Returns:
			0:	Success
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure CategoryList
		As
		Begin
			-- Declarations:
			-- Code:
			Select * from Categories
				Order by [Name]
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO


	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: CategoryGet
			- Stored procedure for getting profile categories
			- By category or all
		Parameters:
			@CategoryID:	The category identifier
		Returns:
			0:	Success
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure CategoryGet (@CategoryID int)
		As
		Begin
			-- Declarations:
			-- Code:
			Select * from Categories
				Where [ID] = @CategoryID
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO
	
	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: CategoryAdd
			- Stored procedure to add a new category
		Parameters:
			@Name:			Name of the category
			@Description:	Description of the category
		Returns:
			0:	Success
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure CategoryAdd (@Name varchar(255), @Description varchar(5000))
		As
		Begin
			-- Code:
			Insert into Categories([Name], [Description])
				Values(@Name, @Description)
			Exec CategoryGet @@IDENTITY
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO
	
	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: CategoryUpdate
			- Stored procedure to update a category
		Parameters:
			@CategoryID:	The category identifier
			@Name:			Name of the category
			@Description:	Description of the category
		Returns:
			0:	Success
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure CategoryUpdate (@CategoryID int, @Name varchar(255), @Description varchar(5000))
		As
		Begin
			-- Code:
			Update Categories
				Set [Name] = @Name,
					[Description] = @Description
				Where [ID] = @CategoryID
			Exec CategoryGet @CategoryID
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO
	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: CategoryRemove
			- Stored procedure to remove a category
			- Removes the category and all links to profiles 
		Parameters:
			@CategoryID:	The category identifier
		Returns:
			0:	Success
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure CategoryRemove (@CategoryID int)
		As
		Begin
			-- Code:
			Delete From ProfCatLink
				Where [CategoryID] = @CategoryID
			Delete From Categories
				Where [ID] = @CategoryID
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO

	
/*	-----------------------------------------------------------------------
	Create Custom recording procedures
	-----------------------------------------------------------------------	*/
	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: RecordYou
			- Stored procedure to record personal properties to the profile
			- Adds a new record based (or updates existing) based on cellphone
			  as unique identifier.
		Parameters:
			...
		Returns:
			0:	Success, Selection is the Profile ID
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure RecordYou (
			@CategoryID int,
			@Title varchar(10),
			@Firstname varchar(50),
			@Surname varchar(50),
			@Email varchar(100),
			@Cellphone varchar(30),
			@Age varchar(10),
			@Profession varchar(50),
			@Customer varchar(5),
			@Registered varchar(5)
		)
		As
		Begin
			-- Declarations:
			Declare @profid int
			-- Code:
			Set @profid = (Select [ID] from Profiles Where [Cellphone] = @Cellphone)
			If @profid IS Not Null
				Begin
					Update Profiles Set
						[Title] = @Title, 
						[Firstname] = @Firstname, 
						[Surname] = @Surname, 
						[Email] = @Email, 
						[Cellphone] = @Cellphone, 
						[Age] = @Age, 
						[Profession] = @Profession, 
						[Customer] = @Customer, 
						[Registered] = @Registered  
					Where [ID] = @profid
					Update ProfCatLink Set
						[CategoryID] = @CategoryID  
					Where [ProfileID] = @profid
				End
			Else
				Begin
					Insert into Profiles(
						[StatusID], 
						[Title], 
						[Firstname], 
						[Surname], 
						[Email], 
						[Cellphone], 
						[Age], 
						[Profession], 
						[Customer], 
						[Registered], 
						[InitDate]
					) Values(
						1, @Title, @Firstname, @Surname, @Email, @Cellphone, @Age, @Profession, @Customer, @Registered, GetDate()
					)
					Set @profid = @@IDENTITY
					Insert into ProfCatLink([ProfileID], [CategoryID])
						Values(@profid, @CategoryID)
				End
			Select @profid as [ID]
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO
	
	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: RecordCell
			- Stored procedure to record cellphone properties to the profile
			- Adds a new record based (or updates existing) based on profile id.
		Parameters:
			...
		Returns:
			0:	Success, Selection is the Profile ID
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure RecordCell (
			@ProfileID int,
			@HowOften int,
			@Choose varchar(100),
			@ChooseOther varchar(255),
			@Use varchar(100),
			@UseOther varchar(255),
			@Costs varchar(10),
			@Pay varchar(10),
			@PayOther varchar(255),
			@Contract varchar(10)
		)
		As
		Begin
			-- Declarations:
			Declare @profid int
			-- Code:
			Set @profid = (Select [ProfileID] from ProfileCell Where [ProfileID] = @ProfileID)
			If @profid IS Not Null
				Begin
					Update ProfileCell Set
						[HowOften] = @HowOften, 
						[Choose] = @Choose, 
						[ChooseOther] = @ChooseOther, 
						[Use] = @Use, 
						[UseOther] = @UseOther, 
						[Costs] = @Costs, 
						[Pay] = @Pay, 
						[PayOther] = @PayOther, 
						[Contract] = @Contract  
					Where [ProfileID] = @ProfileID
				End
			Else
				Begin
					Insert into ProfileCell (
						[ProfileID], 
						[HowOften], 
						[Choose], 
						[ChooseOther], 
						[Use], 
						[UseOther], 
						[Costs], 
						[Pay], 
						[PayOther], 
						[Contract]
					) Values(
						@ProfileID, @HowOften, @Choose, @ChooseOther, @Use, @UseOther, 
						@Costs, @Pay, @PayOther, @Contract
					)
				End
			Exec ProfileGet @profid
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO


	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: RecordSite
			- Stored procedure to record personal properties to the profile
			- Adds a new record based (or updates existing) based on profile id.
		Parameters:
			...
		Returns:
			0:	Success, Selection is the Profile ID
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure RecordSite (
			@ProfileID int,
			@Think int,
			@ThinkWhy varchar(255),
			@ChangeMost varchar(255),
			@Change varchar(255),
			@ChangeLeast varchar(255),
			@LikeMost varchar(255),
			@Like varchar(255),
			@LikeLeast varchar(255),
			@Nav int,
			@NavWhy varchar(255),
			@Looks int,
			@LooksWhy varchar(255),
			@Speed int,
			@More varchar(2000)
		)
		As
		Begin
			-- Declarations:
			Declare @profid int
			-- Code:
			Set @profid = (Select [ProfileID] from ProfileSite Where [ProfileID] = @ProfileID)
			If @profid IS Not Null
				Begin
					Update ProfileSite Set
						[Think] = @Think, 
						[ThinkWhy] = @ThinkWhy, 
						[ChangeMost] = @ChangeMost, 
						[Change] = @Change, 
						[ChangeLeast] = @ChangeLeast, 
						[LikeMost] = @LikeMost, 
						[Like] = @Like, 
						[LikeLeast] = @LikeLeast, 
						[Nav] = @Nav, 
						[NavWhy] = @NavWhy, 
						[Looks] = @Looks, 
						[LooksWhy] = @LooksWhy, 
						[Speed] = @Speed, 
						[More] = @More  
					Where [ProfileID] = @ProfileID
				End
			Else
				Begin
					Insert into ProfileSite (
						[ProfileID], 
						[Think], 
						[ThinkWhy], 
						[ChangeMost], 
						[Change], 
						[ChangeLeast], 
						[LikeMost], 
						[Like], 
						[LikeLeast], 
						[Nav], 
						[NavWhy], 
						[Looks], 
						[LooksWhy], 
						[Speed], 
						[More]
					) Values(
						@ProfileID, @Think, @ThinkWhy, @ChangeMost, @Change, @ChangeLeast, @LikeMost, @Like, 
						@LikeLeast, @Nav, @NavWhy, @Looks, @LooksWhy, @Speed, @More
					)
				End
			Exec ProfileGet @profid
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO

	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: RecordHome
			- Stored procedure to record personal properties to the profile
			- Adds a new record based (or updates existing) based on profile id.
		Parameters:
			...
		Returns:
			0:	Success, Selection is the Profile ID
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure RecordHome (
			@ProfileID int,
			@Think int,
			@ThinkWhy varchar(255),
			@Separate int,
			@SeparateWhy varchar(255),
			@ChangeMost varchar(255),
			@Change varchar(255),
			@ChangeLeast varchar(255),
			@LikeMost varchar(255),
			@Like varchar(255),
			@LikeLeast varchar(255),
			@Prefer varchar(100),
			@PreferOther varchar(255),
			@BypassMost varchar(255),
			@Bypass varchar(255),
			@BypassLeast varchar(255),
			@More varchar(2000)
		)
		As
		Begin
			-- Declarations:
			Declare @profid int
			-- Code:
			Set @profid = (Select [ProfileID] from ProfileHome Where [ProfileID] = @ProfileID)
			If @profid IS Not Null
				Begin
					Update ProfileHome Set
						[Think] = @Think, 
						[ThinkWhy] = @ThinkWhy, 
						[Separate] = @Separate, 
						[SeparateWhy] = @SeparateWhy, 
						[ChangeMost] = @ChangeMost, 
						[Change] = @Change, 
						[ChangeLeast] = @ChangeLeast, 
						[LikeMost] = @LikeMost, 
						[Like] = @Like, 
						[LikeLeast] = @LikeLeast, 
						[Prefer] = @Prefer, 
						[PreferOther] = @PreferOther, 
						[BypassMost] = @BypassMost, 
						[Bypass] = @Bypass, 
						[BypassLeast] = @BypassLeast, 
						[More] = @More  
					Where [ProfileID] = @ProfileID
				End
			Else
				Begin
					Insert into ProfileHome (
						[ProfileID], 
						[Think], 
						[ThinkWhy], 
						[Separate], 
						[SeparateWhy], 
						[ChangeMost], 
						[Change], 
						[ChangeLeast], 
						[LikeMost], 
						[Like], 
						[LikeLeast], 
						[Prefer], 
						[PreferOther], 
						[BypassMost], 
						[Bypass], 
						[BypassLeast], 
						[More]
					) Values(
						@ProfileID, @Think, @ThinkWhy, @Separate, @SeparateWhy, @ChangeMost, @Change, @ChangeLeast, 
						@LikeMost, @Like, @LikeLeast, @Prefer, @PreferOther, @BypassMost, @Bypass, @BypassLeast, @More
					)
				End
			Exec ProfileGet @profid
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO

	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: RecordBilling
			- Stored procedure to record personal properties to the profile
			- Adds a new record based (or updates existing) based on profile id.
		Parameters:
			...
		Returns:
			0:	Success, Selection is the Profile ID
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure RecordBilling (
			@ProfileID int,
			@Prefer varchar(100),
			@Think int,
			@ThinkWhy varchar(255),
			@ChangeMost varchar(255),
			@Change varchar(255),
			@ChangeLeast varchar(255),
			@LikeMost varchar(255),
			@Like varchar(255),
			@LikeLeast varchar(255),
			@Add varchar(10),
			@AddWhat varchar(255),
			@More varchar(2000)
		)
		As
		Begin
			-- Declarations:
			Declare @profid int
			-- Code:
			Set @profid = (Select [ProfileID] from ProfileBilling Where [ProfileID] = @ProfileID)
			If @profid IS Not Null
				Begin
					Update ProfileBilling Set
							[Prefer] = @Prefer, 
							[Think] = @Think, 
							[ThinkWhy] = @ThinkWhy, 
							[ChangeMost] = @ChangeMost, 
							[Change] = @Change, 
							[ChangeLeast] = @ChangeLeast, 
							[LikeMost] = @LikeMost, 
							[Like] = @Like, 
							[LikeLeast] = @LikeLeast, 
							[Add] = @Add, 
							[AddWhat] = @AddWhat, 
							[More] = @More  
					Where 	[ProfileID] = @ProfileID
				End
			Else
				Begin
					Insert into ProfileBilling (
							[ProfileID], 
							[Prefer], 
							[Think], 
							[ThinkWhy], 
							[ChangeMost], 
							[Change], 
							[ChangeLeast], 
							[LikeMost], 
							[Like], 
							[LikeLeast], 
							[Add], 
							[AddWhat], 
							[More]
					) Values(
						@ProfileID, @Prefer, @Think, @ThinkWhy, @ChangeMost, @Change, 
						@ChangeLeast, @LikeMost, @Like, @LikeLeast, @Add, @AddWhat, @More
					)
				End
			Exec ProfileGet @profid
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO

	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: RecordService
			- Stored procedure to record personal properties to the profile
			- Adds a new record based (or updates existing) based on profile id.
		Parameters:
			...
		Returns:
			0:	Success, Selection is the Profile ID
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure RecordService (
			@ProfileID int,
			@Prefer varchar(100),
			@PreferOther varchar(255),
			@PreferWhy varchar(255),
			@Think int,
			@ThinkWhy varchar(255),
			@Site varchar(10),
			@SiteWhy varchar(255),
			@AddMost varchar(255),
			@Add varchar(255),
			@AddLeast varchar(255),
			@More varchar(2000)
		)
		As
		Begin
			-- Declarations:
			Declare @profid int
			-- Code:
			Set @profid = (Select [ProfileID] from ProfileService Where [ProfileID] = @ProfileID)
			If @profid IS Not Null
				Begin
					Update ProfileService Set
							[Prefer] = @Prefer, 
							[PreferOther] = @PreferOther, 
							[PreferWhy] = @PreferWhy, 
							[Think] = @Think, 
							[ThinkWhy] = @ThinkWhy, 
							[Site] = @Site, 
							[SiteWhy] = @SiteWhy, 
							[AddMost] = @AddMost, 
							[Add] = @Add, 
							[AddLeast] = @AddLeast, 
							[More] = @More  
					Where 	[ProfileID] = @ProfileID
				End
			Else
				Begin
					Insert into ProfileService (
							[ProfileID], 
							[Prefer], 
							[PreferOther], 
							[PreferWhy], 
							[Think], 
							[ThinkWhy], 
							[Site], 
							[SiteWhy], 
							[AddMost], 
							[Add], 
							[AddLeast], 
							[More]
					) Values(
						@ProfileID, @Prefer, @PreferOther, @PreferWhy, @Think, @ThinkWhy, 
						@Site, @SiteWhy, @AddMost, @Add, @AddLeast, @More
					)
				End
			Exec ProfileGet @profid
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO

	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: RecordInternet
			- Stored procedure to record personal properties to the profile
			- Adds a new record based (or updates existing) based on profile id.
		Parameters:
			...
		Returns:
			0:	Success, Selection is the Profile ID
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure RecordInternet (
			@ProfileID int,
			@Know varchar(10),
			@Location varchar(50),
			@UseMost varchar(255),
			@Use varchar(255),
			@UseLeast varchar(255),
			@ImportantMost varchar(255),
			@Important varchar(255),
			@ImportantLeast varchar(255),
			@AddMost varchar(255),
			@Add varchar(255),
			@AddLeast varchar(255),
			@More varchar(2000)
		)
		As
		Begin
			-- Declarations:
			Declare @profid int
			-- Code:
			Set @profid = (Select [ProfileID] from ProfileInternet Where [ProfileID] = @ProfileID)
			If @profid IS Not Null
				Begin
					Update ProfileInternet Set
						[Know] = @Know, 
						[Location] = @Location, 
						[UseMost] = @UseMost, 
						[Use] = @Use, 
						[UseLeast] = @UseLeast, 
						[ImportantMost] = @ImportantMost, 
						[Important] = @Important, 
						[ImportantLeast] = @ImportantLeast, 
						[AddMost] = @AddMost, 
						[Add] = @Add, 
						[AddLeast] = @AddLeast, 
						[More] = @More  
					Where [ProfileID] = @ProfileID
				End
			Else
				Begin
					Insert into ProfileInternet (
						[ProfileID], 
						[Know], 
						[Location], 
						[UseMost], 
						[Use], 
						[UseLeast], 
						[ImportantMost], 
						[Important], 
						[ImportantLeast], 
						[AddMost], 
						[Add], 
						[AddLeast], 
						[More]
					) Values(
						@ProfileID, @Know, @Location, @UseMost, @Use, @UseLeast, @ImportantMost, 
						@Important, @ImportantLeast, @AddMost, @Add, @AddLeast, @More
					)
				End
			Exec ProfileGet @profid
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO

	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: RecordTesting
			- Stored procedure to record personal properties to the profile
			- Adds a new record based (or updates existing) based on profile id.
		Parameters:
			...
		Returns:
			0:	Success, Selection is the Profile ID
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure RecordTesting (
			@ProfileID int,
			@Testing varchar(10)
		)
		As
		Begin
			-- Declarations:
			-- Code:
			Update Profiles Set
				[Testing] = @Testing
			Where [ID] = @ProfileID
			Exec ProfileGet @ProfileID
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO

	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: RecordGet
			- Stored procedure for getting all recorded profile info
			- By profile or all
		Parameters:
			@ProfileID:	The profile identifier
		Returns:
			0:	Success
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		CREATE Procedure RecordGet (@ProfileID int)
		As
		Begin
			-- Declarations:
			-- Code:
			Select 
				[ID] = Profiles.ID,
				[StatusID],
				[CategoryID],
				[CategoryName] = Categories.Name,
				[Title],
				[Firstname],
				[Surname],
				[Email],
				[Cellphone],
				-- You
				[Age],
				[Profession],
				[Customer],
				[Registered],
				[Testing],
				[InitDate],
				-- Cell
				[CellHowOften] = ProfileCell.HowOften, 
				[CellChoose] = ProfileCell.Choose, 
				[CellChooseOther] = ProfileCell.ChooseOther, 
				[CellUse] = ProfileCell.[Use], 
				[CellUseOther] = ProfileCell.UseOther, 
				[CellCosts] = ProfileCell.Costs, 
				[CellPay] = ProfileCell.Pay, 
				[CellPayOther] = ProfileCell.PayOther, 
				[CellContract] = ProfileCell.Contract,
				-- Site         
				[SiteThink] = ProfileSite.Think, 
				[SiteThinkWhy] = ProfileSite.ThinkWhy, 
				[SiteChangeMost] = ProfileSite.ChangeMost, 
				[SiteChange] = ProfileSite.Change, 
				[SiteChangeLeast] = ProfileSite.ChangeLeast, 
				[SiteLikeMost] = ProfileSite.LikeMost, 
				[SiteLike] = ProfileSite.[Like], 
				[SiteLikeLeast] = ProfileSite.LikeLeast, 
				[SiteNav] = ProfileSite.Nav, 
				[SiteNavWhy] = ProfileSite.NavWhy, 
				[SiteLooks] = ProfileSite.Looks, 
				[SiteLooksWhy] = ProfileSite.LooksWhy, 
				[SiteSpeed] = ProfileSite.Speed, 
				[SiteMore] = ProfileSite.More,
				-- Home         
				[HomeThink] = ProfileHome.Think, 
				[HomeThinkWhy] = ProfileHome.ThinkWhy, 
				[HomeSeparate] = ProfileHome.Separate, 
				[HomeSeparateWhy] = ProfileHome.SeparateWhy, 
				[HomeChangeMost] = ProfileHome.ChangeMost, 
				[HomeChange] = ProfileHome.Change, 
				[HomeChangeLeast] = ProfileHome.ChangeLeast, 
				[HomeLikeMost] = ProfileHome.LikeMost, 
				[HomeLike] = ProfileHome.[Like], 
				[HomeLikeLeast] = ProfileHome.LikeLeast, 
				[HomePrefer] = ProfileHome.Prefer, 
				[HomePreferOther] = ProfileHome.PreferOther, 
				[HomeBypassMost] = ProfileHome.BypassMost, 
				[HomeBypass] = ProfileHome.Bypass, 
				[HomeBypassLeast] = ProfileHome.BypassLeast, 
				[HomeMore] = ProfileHome.More,
				-- Billing       
				[BillingPrefer] = ProfileBilling.Prefer, 
				[BillingThink] = ProfileBilling.Think, 
				[BillingThinkWhy] = ProfileBilling.ThinkWhy, 
				[BillingChangeMost] = ProfileBilling.ChangeMost, 
				[BillingChange] = ProfileBilling.Change, 
				[BillingChangeLeast] = ProfileBilling.ChangeLeast, 
				[BillingLikeMost] = ProfileBilling.LikeMost, 
				[BillingLike] = ProfileBilling.[Like], 
				[BillingLikeLeast] = ProfileBilling.LikeLeast, 
				[BillingAdd] = ProfileBilling.[Add], 
				[BillingAddWhat] = ProfileBilling.AddWhat, 
				[BillingMore] = ProfileBilling.More,
				-- Service       
				[ServicePrefer] = ProfileService.Prefer, 
				[ServicePreferOther] = ProfileService.PreferOther,
				[ServicePreferWhy] = ProfileService.PreferWhy, 
				[ServiceThink] = ProfileService.Think, 
				[ServiceThinkWhy] = ProfileService.ThinkWhy, 
				[ServiceSite] = ProfileService.Site, 
				[ServiceSiteWhy] = ProfileService.SiteWhy, 
				[ServiceAddMost] = ProfileService.AddMost, 
				[ServiceAdd] = ProfileService.[Add], 
				[ServiceAddLeast] = ProfileService.AddLeast, 
				[ServiceMore] = ProfileService.More,
				-- Internet      
				[InternetKnow] = ProfileInternet.Know, 
				[InternetLocation] = ProfileInternet.Location, 
				[InternetUseMost] = ProfileInternet.UseMost, 
				[InternetUse] = ProfileInternet.[Use], 
				[InternetUseLeast] = ProfileInternet.UseLeast, 
				[InternetImportantMost] = ProfileInternet.ImportantMost, 
				[InternetImportant] = ProfileInternet.Important, 
				[InternetImportantLeast] = ProfileInternet.ImportantLeast, 
				[InternetAddMost] = ProfileInternet.AddMost, 
				[InternetAdd] = ProfileInternet.[Add], 
				[InternetAddLeast] = ProfileInternet.AddLeast, 
				[InternetMore] = ProfileInternet.More
			From ProfCatLink
				Inner Join Categories on ProfCatLink.CategoryID = Categories.ID
				Inner Join Profiles on ProfCatLink.ProfileID = Profiles.ID
				Left Outer Join ProfileCell on ProfileCell.ProfileID = Profiles.ID
				Left Outer Join ProfileSite on ProfileSite.ProfileID = Profiles.ID
				Left Outer Join ProfileHome on ProfileHome.ProfileID = Profiles.ID
				Left Outer Join ProfileBilling on ProfileBilling.ProfileID = Profiles.ID
				Left Outer Join ProfileService on ProfileService.ProfileID = Profiles.ID
				Left Outer Join ProfileInternet on ProfileInternet.ProfileID = Profiles.ID
				Where ProfCatLink.ProfileID = @ProfileID
		End
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO
	
	
	SET QUOTED_IDENTIFIER ON 
	GO
	SET ANSI_NULLS ON 
	GO
	/*	-----------------------------------------------------------------------
		Procedure: Record
			- Stored procedure to record personal properties to the profile
			- Adds a new record based (or updates existing) based on profile id.
		Parameters:
			...
		Returns:
			0:	Success, Selection is the Profile ID
			n:	Some error condition
		-----------------------------------------------------------------------	*/
		/*
		CREATE Procedure Record (
			@ProfileID int,
			@xxxxx varchar(10),
			@More varchar(2000)
		)
		As
		Begin
			-- Declarations:
			Declare @profid int
			-- Code:
			Set @profid = (Select [ProfileID] from ProfileX Where [ProfileID] = @ProfileID)
			If @profid IS Not Null
				Begin
					Update ProfileX Set
						[xxxxx] = @xxxxx, 
						[More] = @More  
					Where [ProfileID] = @ProfileID
				End
			Else
				Begin
					Insert into ProfileX (
						[ProfileID], 
						[xxxxx], 
						[More]
					) Values(
						@ProfileID, @xxxxx, @More
					)
				End
			Exec ProfileGet @profid
		End
		*/
	GO
	SET QUOTED_IDENTIFIER OFF 
	GO
	SET ANSI_NULLS ON 
	GO
/*	-----------------------------------------------------------------------
	Create Function(s)
	-----------------------------------------------------------------------	*/
	
	
/*	-----------------------------------------------------------------------
	Add default data into tables
	-----------------------------------------------------------------------	*/
	-- 'Forms' categories
	exec CategoryAdd 'barenec', 'Bare necessities'
	exec CategoryAdd 'morenec', 'Beyond necessity'
	exec CategoryAdd 'invogue', 'In Vogue'
	exec CategoryAdd 'business', 'Business Matters'
	exec CategoryAdd 'fun', 'FUNdamentalist'
	exec CategoryAdd 'gadget', 'Mr Gadget'
	-- add default profile
	exec ProfileAdd 1, 'Hon', 'System', 'Administrator', 'sysadmin@umlungu.com', '0811112233'
	
